<project name="JSFunctions" app="Snap! 4.0, http://snap.berkeley.edu" version="1"><notes></notes><thumbnail></thumbnail><stage name="Stage" width="480" height="360" costume="0" tempo="60" threadsafe="false" lines="round" codify="false" scheduled="false" id="1"><pentrails></pentrails><costumes><list id="2"></list></costumes><sounds><list id="3"></list></sounds><variables></variables><blocks></blocks><scripts></scripts><sprites><sprite name="Sprite" idx="1" x="34.00441814031274" y="-3.328227907064843" heading="105" scale="1" rotation="1" draggable="true" costume="0" color="80,80,80" pen="tip" id="8"><costumes><list id="9"></list></costumes><sounds><list id="10"></list></sounds><variables></variables><blocks></blocks><scripts><script x="20" y="20"><block s="evaluate"><block s="reportJSFunction"><list><l>a</l><l>b</l></list><l>return +a + +b</l></block><list><l>3</l><l>4</l></list></block></script><script x="20" y="70.99999999999999"><block s="doDeclareVariables"><list><l>mult</l></list></block><block s="doSetVar"><l>mult</l><block s="reportJSFunction"><list><l>a</l><l>b</l></list><l>return +a * +b</l></block></block><block s="doSayFor"><block s="evaluate"><block var="mult"/><list><l>5</l><l>2</l></list></block><l>2</l></block></script><script x="20" y="166"><block s="doRun"><block s="reportJSFunction"><list><l>degrees</l></list><l>this.turn(+degrees)</l></block><list><l>15</l></list></block></script><script x="20" y="223"><block s="evaluate"><block s="reportJSFunction"><list><l>list</l><l>start</l><l>end</l></list><l>return new List(list.asArray().slice(+start - 1, +end))</l></block><list><block s="reportNewList"><list><l>foo</l><l>bar</l><l>baz</l><l>qux</l><l>frob</l><l>spam</l><l>garply</l></list></block><l>3</l><l>5</l></list></block></script><script x="20" y="292"><custom-block s="copy %l from %n to %n"><block s="reportNewList"><list><l>foo</l><l>bar</l><l>baz</l><l>qux</l><l>frob</l><l>spam</l><l>garply</l></list></block><l>3</l><l>5</l></custom-block></script><script x="20" y="328.99999999999994"><block s="clear"></block></script><script x="20" y="365"><block s="doRun"><block s="reportJSFunction"><list><l>size</l><l>level</l></list><l>var myself = this;&#xD;&#xD;function sierp (length, depth) {&#xD;  if (depth) {&#xD;    for (var i = 0; i &lt; 3; i +=1) {&#xD;      sierp(length / 2, depth - 1);&#xD;      myself.forward(length)&#xD;      myself.turn(120);&#xD;    }&#xD;  } &#xD;}&#xD;&#xD;this.clear();&#xD;this.up();&#xD;this.gotoXY(0, 0);&#xD;this.down();&#xD;for (var i = 0; i &lt; 12; i += 1) {&#xD;  sierp(+size, +level);&#xD;  this.turn(30);&#xD;}&#xD;this.up();</l></block><list><l>200</l><l>5</l></list></block></script><script x="20" y="684"><custom-block s="label %txt of size %n"><l>Hello!</l><l>36</l></custom-block></script><script x="20" y="722.9999999999999"><custom-block s="JS map %repRing over %l"><block s="reifyReporter"><autolambda><block s="reportJoinWords"><list><l>hello </l><l></l></list></block></autolambda><list></list></block><block s="reportNewList"><list><l>foo</l><l>bar</l><l>baz</l></list></block></custom-block></script><script x="20" y="766.0000000000001"><custom-block s="speak %s"><l>Hello, World!</l></custom-block></script></scripts></sprite></sprites></stage><hidden></hidden><headers></headers><code></code><blocks><block-definition s="copy %&apos;list&apos; from %&apos;start&apos; to %&apos;end&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%l"></input><input type="%n">1</input><input type="%n">10</input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>list</l><l>start</l><l>end</l></list><l>return new List(list.asArray().slice(+start - 1, +end))</l></block><list><block var="list"/><block var="start"/><block var="end"/></list></block></block></script></block-definition><block-definition s="label %&apos;text&apos; of size %&apos;size&apos;" type="command" category="pen"><header></header><code></code><inputs><input type="%txt">Hello!</input><input type="%n">12</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>text</l><l>size</l></list><l>var stage = this.parentThatIsA(StageMorph),&#xD;    context = stage.penTrails().getContext(&apos;2d&apos;),&#xD;    rotation = radians(this.direction() - 90),&#xD;    trans = new Point(&#xD;      this.center().x - stage.left(),&#xD;      this.center().y - stage.top()&#xD;    ),&#xD;    isWarped = this.Warped,&#xD;    len,&#xD;    pos;&#xD;&#xD;if (isWarped) {endWarp(); }&#xD;context.save();&#xD;context.font = size + &apos;px monospace&apos;;&#xD;context.textAlign = &apos;left&apos;;&#xD;context.textBaseline = &apos;alphabetic&apos;;&#xD;context.fillStyle = this.color.toString();&#xD;len = context.measureText(text).width;&#xD;trans = trans.multiplyBy(1 / stage.scale);&#xD;context.translate(trans.x, trans.y);&#xD;context.rotate(rotation);&#xD;context.fillText(text, 0, 0);&#xD;context.translate(-trans.x, -trans.y);&#xD;context.restore();&#xD;pos = new Point(&#xD;  len * Math.sin(radians(this.direction())),&#xD;  len * Math.cos(radians(this.direction())));&#xD;pos = pos.add(new Point(this.xPosition(), this.yPosition()));&#xD;this.gotoXY(pos.x, pos.y, false);&#xD;this.changed();&#xD;if (isWarped) {this.startWarp(); }&#xD;stage.changed();</l></block><list><block var="text"/><block var="size"/></list></block></script></block-definition><block-definition s="JS map %&apos;reporter&apos; over %&apos;list&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%repRing"></input><input type="%l"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>reporter</l><l>list</l><l>process</l></list><l>// process.context.inputs:&#xD;// [0] - reporter&#xD;// [1] - list (original source)&#xD;// ---------------------------------&#xD;// [2..n] - result values (target)&#xD;&#xD;if (process.context.inputs.length - 2 === list.length()) {&#xD;  process.returnValueToParentContext(&#xD;    new List(process.context.inputs.slice(2))&#xD;  );&#xD;  return;&#xD;}&#xD;var next = list.at(process.context.inputs.length - 1);&#xD;process.pushContext();&#xD;process.evaluate(reporter, new List([next]));</l></block><list><block var="reporter"/><block var="list"/></list></block></block></script></block-definition><block-definition s="speak %&apos;text&apos;" type="command" category="sound"><header></header><code></code><inputs><input type="%s">Hello, World!</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>msg</l></list><l>window.speechSynthesis.speak(new SpeechSynthesisUtterance(msg))</l></block><list><block var="text"/></list></block></script></block-definition></blocks><variables></variables></project>